<?php
namespace app\api\controller;

use lib\Db;
use lib\Response;

class Article extends Common{

    /**
     * 文章列表
     * @return array
     */
    function articleList(){
        $list = Db::name('article a')->join('user u', 'u.id = a.uid', 'left')
            ->limit($this->post['page'] * $this->post['pageRow'], $this->post['pageRow'])
            ->where(['book_id'=>$this->post['book_id']])->select();
        return Response::success('ok', $list);
    }

    /**
     * 日记列表
     * @return array
     */
    function bookArticle(){
        if(!is_numeric($this->post['book_id'])){
            return Response::error('获取日记本ID失败!');
        }
        $list = Db::name('article')->limit($this->post['page'] * $this->post['pageRow'], $this->post['pageRow'])
            ->where(['book_id'=>$this->post['book_id']])->select();
        return Response::success('ok', $list);
    }

    /**
     * 文章详情
     * @return array
     */
    function detail(){
        if(!is_numeric($this->post['id'])){
            return Response::error('获取id失败!');
        }
        $info = Db::name('article')->where(['id'=>$this->post['id']])->find();
        return Response::success('ok', $info);
    }

}